#include "Logic_PowerStapler.h"

//*********************************************************************
/* check battery install
 * input void 
 * return: 0- install is ok, NORMAL_WORK 1- POWERSTAPLER_ADAPTER_NO_INSTALL
 * author: Guichuan.He
 * date: 2016-10-09
*/
//**********************************************************************
uint Logic_PowerManage_CheckBattery()
{
    unsigned char Battery_Status;
    if(  Device_LTC2943_CheckALCC() == 1)
    {
        return 0;
    }
    else
    {
        Battery_Status = Device_LTC2943_ReadByte(0x00);
    }
    
    if( (Battery_Status & 0x40) == 0x40 )
        return POWER_CURRENT_ALERT;
    else if( (Battery_Status & 0x20) == 0x20 )
        return POWER_ACCUMULATED_CHARGE_OVER_UNDERFLOW;
    else if( (Battery_Status & 0x10) == 0x10 )
        return POWER_TEMPERATURE_ALERT;
     else if( (Battery_Status & 0x08) == 0x08 )
        return POWER_CHARGE_ALERT_HIGH;
     else if( (Battery_Status & 0x04) == 0x04 )
         return POWER_CHARGE_ALERT_LOW;
     else if( (Battery_Status & 0x02) == 0x02 )
         return POWER_CHARGE_VOLTAGE_ALERT  ;
     else if( (Battery_Status & 0x01) == 0x01 )
        return POWER_UNDERVOLTAGE_LOCKOUT_ALERT;
     else
         return 0;
}